package a66weding.com.jiehuntong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.Diy_DinghunActivity;
import a66weding.com.jiehuntong.beans.Diy_GoodsBean;

/**
 * Created by admin on 2016/6/20.
 */
public class MyDinghunAdapter extends BaseAdapter {
    private Context context;
    private List<Diy_GoodsBean> list;
    // 用来导入布局
    private LayoutInflater inflater = null;

    public MyDinghunAdapter(Diy_DinghunActivity diy_dinghunActivity, List<Diy_GoodsBean> list) {
        this.context = diy_dinghunActivity;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            // 获得ViewHolder对象
            holder = new ViewHolder();
            // 导入布局并赋值给convertview
            convertView = inflater.inflate(R.layout.diy_item_dinghun, null);
            holder.tv_act = (TextView) convertView.findViewById(R.id.item_dhact_tv);
            holder.tv_cont = (TextView) convertView.findViewById(R.id.item_dhcont_tv);
            holder.iv_icon = (ImageView) convertView.findViewById(R.id.item_dhicon_iv);
            holder.tv_name = (TextView) convertView.findViewById(R.id.item_dhname_tv);
            holder.tv_cos = (TextView) convertView.findViewById(R.id.item_dhcost_tv);
            holder.tv_cut = (TextView) convertView.findViewById(R.id.item_dhcut_tv);

            // 为view设置标签
            convertView.setTag(holder);
        } else {
            // 取出holder
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_act.setText(list.get(position).hotAct);
        holder.tv_cont.setText(list.get(position).hotCont);
        holder.iv_icon.setImageResource(list.get(position).hotIcon);
        holder.tv_name.setText(list.get(position).hotName);
        holder.tv_cos.setText(list.get(position).costPri);
        holder.tv_cut.setText(list.get(position).cutPri);
        return convertView;
    }

    public static class ViewHolder {
        public TextView tv_act, tv_cont, tv_name, tv_cos, tv_cut;
        public ImageView iv_icon;
    }
}
